local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
local __TS__StringSubstr = ____lualib.__TS__StringSubstr
local __TS__Number = ____lualib.__TS__Number
local __TS__SourceMapTraceBack = ____lualib.__TS__SourceMapTraceBack
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["10"] = 2,["11"] = 2,["12"] = 3,["13"] = 3,["14"] = 4,["15"] = 4,["16"] = 5,["17"] = 5,["18"] = 6,["19"] = 6,["20"] = 7,["21"] = 7,["22"] = 8,["23"] = 8,["24"] = 9,["25"] = 9,["26"] = 11,["27"] = 12,["28"] = 15,["29"] = 15,["30"] = 15,["31"] = 21,["32"] = 21,["33"] = 16,["34"] = 17,["35"] = 22,["36"] = 23,["37"] = 24,["38"] = 25,["39"] = 26,["40"] = 27,["41"] = 27,["42"] = 27,["43"] = 28,["46"] = 32,["47"] = 33,["50"] = 37,["51"] = 38,["54"] = 27,["55"] = 27,["56"] = 21,["57"] = 48,["58"] = 49,["59"] = 49,["60"] = 49,["61"] = 50,["62"] = 49,["63"] = 49,["64"] = 48,["65"] = 57,["66"] = 58,["67"] = 57,["68"] = 64,["69"] = 65,["72"] = 69,["73"] = 70,["74"] = 71,["75"] = 71,["76"] = 71,["77"] = 72,["78"] = 73,["79"] = 74,["80"] = 71,["81"] = 71,["82"] = 76,["83"] = 77,["84"] = 78,["85"] = 79,["87"] = 64,["88"] = 86,["89"] = 87,["90"] = 88,["91"] = 89,["92"] = 90,["93"] = 91,["94"] = 92,["95"] = 86});
local ____exports = {}
local ____ui = require("kernel.util.ui")
local KUi = ____ui.default
local ____ui = require("data.ui.index")
local UI = ____ui.default
local ____table = require("kernel.util.table")
local KTable = ____table.default
local ____unit_type = require("kernel.util.unit_type")
local KUnitType = ____unit_type.default
local ____event_util = require("kernel.util.event_util")
local EventUtil = ____event_util.default
local ____unit = require("kernel.util.unit")
local KUnit = ____unit.default
local ____cache = require("kernel.util.cache")
local Cache = ____cache.default
local ____ReviveController = require("app.hero.ReviveController")
local ReviveController = ____ReviveController.default
local cache = __TS__New(Cache)
local ____table = __TS__New(KTable, "英雄池")
____exports.default = __TS__Class()
local HeroSelectController = ____exports.default
HeroSelectController.name = "HeroSelectController"
function HeroSelectController.prototype.____constructor(self, player)
    self.player = player
    self.typeIds = {}
    self.count = 3
    self.mainUI = KUi:searchPath(player, UI.HeroSelect)
    self.refreshUI = KUi:searchPath(player, UI.HeroSelectRefreshBtn)
    self:open()
    self.count = self.count + 1
    self:refresh()
    EventUtil:register(
        "TRIGGER_COMPONENT_EVENT",
        function(data)
            if data.__role_id ~= self.player.id then
                return
            end
            if data.__ui_event_name == "RefreshHero" then
                self:refresh()
                return
            end
            if data.__ui_event_name == "SelectHero" then
                self:confirmSelect(__TS__New(KUi, data.__comp_name, self.player))
                return
            end
        end
    )
end
function HeroSelectController.fromPlayer(self, player)
    return cache:get(
        "heroSelect",
        function()
            return __TS__New(____exports.default, player)
        end
    )
end
function HeroSelectController.prototype.open(self)
    self.mainUI:visible(true)
end
function HeroSelectController.prototype.refresh(self)
    if self.count <= 0 then
        return
    end
    local list = ____table:toList({"id", "type"})
    local slist = list:random(2)
    __TS__ArrayForEach(
        slist,
        function(____, item, idx)
            local hui = KUi:searchPath(self.player, UI.HeroSelectBtn[idx + 1])
            hui:setImage(__TS__New(KUnitType, item.type).icon)
            self.typeIds[idx + 1] = item.type
        end
    )
    self.count = self.count - 1
    self.refreshUI:setText(("刷新(" .. tostring(self.count)) .. ")")
    if self.count <= 0 then
        self.refreshUI:disable(true)
    end
end
function HeroSelectController.prototype.confirmSelect(self, ui)
    self.mainUI:visible(false)
    local idx = __TS__Number(__TS__StringSubstr(ui.name, -1)) - 1
    local unit = KUnit:create(self.player, self.typeIds[idx + 1], 0, 0)
    self.player:selectUnit(unit)
    self.player:setData("hero", unit)
    __TS__New(ReviveController, unit)
end
return ____exports
